/**
 * Created with JetBrains WebStorm.
 * User: renji
 * Date: 13/3/13
 * Time: 11:47 AM
 * To change this template use File | Settings | File Templates.
 */

describe('SecurityController', function(){

    var controller;

    beforeEach(function(){
        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();

        App.SecurityController.reopen({

            init:function(){
                this.set('controllers', Em.Object.create({
                    alert: t_alertCtrl,
                    loading: t_loadingCtrl
                }));
            }

        });

        controller = App.SecurityController.create();
    });

    it('should invoke prepareController', function(){
        controller.prepareController();
    });

//    it('should invoke userDisplayName', function(){
//
//        App.getSession().setAttribute('user',{displayName:"User"});
//
//        spyOn(App.getSession().getAttribute('user'), 'displayName');
//
//        controller.userDisplayName();
//
//        expect(App.getSession().getAttribute('user').displayName).toHaveBeenCalled();
//    });

    it('should invoke logout', function(){
        spyOn(controller.get('controllers.alert'), 'showAlert');
        controller.logout(controller);

        expect(controller.get('controllers.alert').showAlert).toHaveBeenCalledWith(App.i18n.getTranslations().get('common.logoutMessage'),jasmine.any(Function),App.i18n.getTranslations().get('title.logout'),App.i18n.getTranslations().get('title.cancel'));
    });


    it("logoutCallback failed method - ", function(){

        // var objE = {errorCode:'code', _errorMessage:'message', getErrorMessage:function(){}};
        var objE = new BreezeException({
            _errorCode:'code',
            _errorMessage:'message'
        });
        spyOn(controller, 'transitionTo');

        controller.logoutCallback(null, objE);
        
        expect(controller.transitionTo).toHaveBeenCalledWith('public.login');
    });

    it("logoutCallback success method - ", function(){

        var objE = undefined;

        var objLogoutSummary = {loginDate:"2013-03-14T20:40:49.068+0800",logoutDate:"2013-03-14T20:56:02.533+0800",duration:"1970-01-01T07:45:13.465+0730"}

        spyOn(controller, 'transitionTo');

        spyOn(App, 'prepareLogout');

        controller.logoutCallback(objLogoutSummary,objE);

        expect(App.prepareLogout).toHaveBeenCalled();

        expect(controller.transitionTo).toHaveBeenCalledWith('public.logout',objLogoutSummary);
    });
});

